/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
    Text, LineColumn, InputLine, SuffixInput, Table, TableBody, TableRow, CCell, InputDatalist,
} from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, RepLink, useItemInputControl,} from "../../common/base";
import {useMeasureInpFilter} from "../../common/hooks";
import {floatInterception} from "../../../common/tool";

export const 检验结果选=['符合要求','不符合要求'];
export const itemA速度差=['行距离','用时间','速差r','仪速度偏','仪速差r'];
export const SpeedBias=
    React.forwardRef(({ children, show ,alone=true,refWidth,label}:InternalItemProps,  ref
    ) => {
        const itemA = React.useMemo(() => {
            return [ ...itemA速度差, '运行速度'];
        }, [ ]);
        const [getInpFilter]=useMeasureInpFilter(null, itemA, );
        const {inp, setInp} = useItemInputControl({ ref });
        const speedVs= floatInterception(inp?.行距离 / inp?.用时间, 4) as unknown as number;
        const resPec=floatInterception(100*(speedVs-inp?.运行速度)/inp?.运行速度, 2);
        const resPec2=floatInterception(100*(inp?.仪速度偏-inp?.运行速度)/inp?.运行速度, 2);
        return (
            <InspectRecordLayout inp={inp} setInp={setInp}  getInpFilter={getInpFilter} show={show}
                                 alone={alone}  label={label!}>
                <Text variant="h5">{label}</Text>
                <Text variant="h5">空载梯级（踏板、胶带）运行速度与名义速度偏差（简易方法）{'>>'}</Text>
                <LineColumn>
                    <InputLine  label='梯级、踏板或胶带实际运行距离S(m)' >
                        <SuffixInput  value={inp?.行距离??''} onSave={txt=> setInp({...inp,行距离: txt || undefined })}>m</SuffixInput>
                    </InputLine>
                    <InputLine  label='运行距离所用的时间t(s)' >
                        <SuffixInput  value={inp?.用时间??''} onSave={txt=> setInp({...inp,用时间: txt || undefined })}>s</SuffixInput>
                    </InputLine>
                </LineColumn>
                梯级、踏板或胶带 运行速度Vs= {floatInterception(inp?.行距离/inp?.用时间, 4)} m/s; 名义速度={inp?.运行速度} m/s; 偏差计算结果：{resPec}%;
                <InputLine label={'检验结果'}>
                    <InputDatalist value={inp?.速差r?? ''} datalist={检验结果选}
                                   onListChange={v => setInp({...inp,速差r: v || undefined }) }/>
                </InputLine>
                <hr/>
                <Text variant="h5" css={{marginTop: '1rem',
                }}>空载梯级（踏板、胶带）运行速度与名义速度偏差（自动扶梯综合检测仪等其他仪器）{'>>'}</Text>
                <InputLine  label='梯级、踏板或胶带运行速度Vs' >
                    <SuffixInput  value={inp?.仪速度偏??''} onSave={txt=> setInp({...inp,仪速度偏: txt || undefined })}>m/s</SuffixInput>
                </InputLine>
                名义速度={inp?.运行速度} m/s; 偏差计算结果：{resPec2}%;
                <InputLine label={'检验结果'}>
                    <InputDatalist value={inp?.仪速差r?? ''} datalist={检验结果选}
                                   onListChange={v => setInp({...inp,仪速差r: v || undefined }) }/>
                </InputLine>
                <br/>
                备注：速度偏差计算结果的判定，当空载梯级（踏板、胶带）运行速度大于名义速度时为正值，反之为负值。
            </InspectRecordLayout>
    );
} );


export const 运行速度偏差= ({orc, rep,label} :{orc:any, rep:any,label:string}
) => {
    const speedVs= floatInterception(orc?.行距离 / orc?.用时间, 4) as unknown as number;
    const resPec=floatInterception(100*(speedVs-orc?.运行速度)/orc?.运行速度, 2);
    const resPec2=floatInterception(100*(orc?.仪速度偏-orc?.运行速度)/orc?.运行速度, 2);
    return <>
        <div css={{"@media print": {paddingBottom: '6rem', pageBreakInside: 'avoid'}}}>
            <Text id={'Limiter'} variant="h4" css={{marginTop: '1rem',
            }}>{label}</Text>
        </div>
        <Table id={'SpeedBias'} fixed={ ["27%", "%", "32%"] }
               css={{borderCollapse: 'collapse', "@media print": {marginTop: '-6rem'}}} tight miniw={800}>
            <TableBody>
                <RepLink rep={rep} tag={'SpeedBias'}>
                    <TableRow><CCell>项目编号</CCell><CCell colSpan={2}>42.7</CCell></TableRow>
                    <TableRow><CCell>检验内容</CCell><CCell>梯级、踏板或胶带实际运行距离S(m)</CCell><CCell>运行距离所用的时间t(s)</CCell></TableRow>
                    <TableRow><CCell>观测数据</CCell><CCell>{orc.行距离 ?? '／'} m</CCell><CCell>{orc.用时间 ?? '／'} s</CCell></TableRow>
                    <TableRow><CCell>梯级、踏板或胶带运行速度Vs</CCell><CCell colSpan={2}>{speedVs ?? '／'} m/s</CCell></TableRow>
                    <TableRow><CCell>计算结果：</CCell><CCell colSpan={2}>{resPec ?? '／'} %</CCell></TableRow>
                    <TableRow><CCell>判断标准</CCell><CCell colSpan={2}>-5%≤(Vs-Vn)/Vn≤5%</CCell></TableRow>
                    <TableRow><CCell>检验结果</CCell><CCell colSpan={2}>{orc.速差r ?? '／'}</CCell></TableRow>
                </RepLink>
            </TableBody>
        </Table>

        <div css={{"@media print": {paddingBottom: '3.5rem', pageBreakInside: 'avoid'}}}>
            <Text variant="h5" css={{marginTop: '1rem',
            }}>空载梯级（踏板、胶带）运行速度与名义速度偏差（自动扶梯综合检测仪等其他仪器）</Text>
        </div>
        <Table fixed={ ["27%", "%", "32%"] }
               css={{borderCollapse: 'collapse', "@media print": {marginTop: '-3.5rem'}}} tight miniw={800}>
            <TableBody>
                <RepLink rep={rep} tag={'SpeedBias'}>
                    <TableRow><CCell>项目编号</CCell><CCell colSpan={2}>42.7</CCell></TableRow>
                    <TableRow><CCell>梯级、踏板或胶带运行速度Vs</CCell><CCell colSpan={2}>{orc?.仪速度偏 ?? '／'} m/s</CCell></TableRow>
                    <TableRow><CCell>计算结果：</CCell><CCell colSpan={2}>{resPec2 ?? '／'} %</CCell></TableRow>
                    <TableRow><CCell>判断标准</CCell><CCell colSpan={2}>-5%≤(Vs-Vn)/Vn≤5%</CCell></TableRow>
                    <TableRow><CCell>检验结果</CCell><CCell colSpan={2}>{orc.仪速差r ?? '／'}</CCell></TableRow>
                </RepLink>
            </TableBody>
        </Table>
        <Text css={{fontSize: '0.75rem'}}>
            备注：速度偏差计算结果的判定，当空载梯级（踏板、胶带）运行速度大于名义速度时为正值，反之为负值。
        </Text>
    </>;
};
